package com.qf.work20250103;

import java.util.ArrayList;

/**
 * @author zdl
 * @date 2025/1/4
 */
class Animal{
    public void play(){};
}
class Dog extends Animal{
    @Override
    public void play() {
        System.out.println("狗会玩儿");
    }
}
class Cat extends Animal{
    @Override
    public void play() {
        System.out.println("猫会玩儿");
    }
}
class Pig extends Animal{
    @Override
    public void play() {
        System.out.println("猪会玩儿");
    }
}
public class Demo3 {
    public static void main(String[] args) {
        ArrayList<Animal> list = new ArrayList<>();
        list.add(new Dog());
        list.add(new Cat());
        list.add(new Pig());
        System.out.println(list.get(1));
        for (Animal animal : list) {
            animal.play();
        }
        System.out.println("======");
        Animal[] animals = new Animal[3];
        animals[0] = new Pig();
        animals[1] = new Dog();
        animals[2] = new Cat();
        for (Animal animal : animals) {
            animal.play();
        }
    }
}
